{% macro page_link(link, page, id=-1) %}
{% if id < 0 %}
    {{ url_for(link, uid=g.user.uid, page=page)}}
{% else %}
    {{ url_for(link, page=page, album_id=id)}}
{% endif %}
{% endmacro %}

{% macro pager(link, page, total_page, id=-1) %}
<div class="list-pagination">
    <div class="ui divider"></div>
    <div class="ui pagination menu">
        {% if page > 1 %}
        <a class="item" href="{{ page_link(link, page=1, id=id) }}">
            1…
        </a>
        <a class="sr-only js-prev-page" href="{{ page_link(link, page=page-1, id=id) }}">上一页</a>
        {% endif %}
        {% for p in range(1 if page == 1 else 2, total_page if page < total_page else total_page+1) %}
            {% if -3 < p - page < 3 %}
            <a class="item{% if p == page %} active{% endif %}" href="{{ page_link(link, page=p, id=id) }}">{{ p }}</a>
            {% endif %}
        {% endfor %}
        {% if page < total_page %}
        <a class="sr-only js-next-page" href="{{ page_link(link, page=page+1, id=id) }}">下一页</a>
        <a class="item" href="{{ page_link(link, page=total_page, id=id) }}">
            …{{ total_page }}
        </a>
        {% endif %}
    </div>
</div>
{% endmacro %}

{% macro like_list(likes) %}
    {% for like in likes %}
      {%- if loop.index0 > 0 %}，{% endif -%}
      <a href="http://www.renren.com/profile.do?id={{like.uid}}" target="_blank">{{ like.name }}</a>
    {%- endfor %}
{% endmacro %}

{% macro comments_list(comments, is_status) %}
<div class="ui feed item-comment{% if is_status %} status-comment{% endif %}">
    {% for comment in comments %}
    <div class="event">
        <div class="label">
            <a href="http://www.renren.com/profile.do?id={{comment.authorId}}" target="_blank">
                <img src="{{ comment.headPic }}">
            </a>
        </div>
        <div class="content">
            <div class="summary">
                <a href="http://www.renren.com/profile.do?id={{comment.authorId}}" target="_blank">{{ comment.authorName }}</a>
                <div class="date">{{ comment.t }}</div>
            </div>
            <div class="extra text">{{ comment.content|safe }}</div>
        </div>
    </div>
    {% endfor %}
</div>
{% endmacro %}

{% macro comments_popup(item) %}
<div class="ui popup">
    <div class="item-like">
        {{ like_list(item.likes) }}
        {% if item.likes|length %}
            等 {{ item.likes|length }} 人点赞。
        {% endif %}
        {{ item.comments|length }} 条评论
    </div>
    {% if item.comments|length %}
    <div class="ui divider"></div>
    {{ comments_list(item.comments, True) }}
    {% endif %}
</div>
{% endmacro %}
